package com.rrd.mex.dw.mr.babel.parser;

import com.alibaba.fastjson.JSONObject;
import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.mexico.BlackListCheckRecord;
import com.ucredit.babel.common.model.mexico.MultiPlatformDetectionRecord;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MultiPlatformDetectionRecordParse extends ParseBase{
    private Text val = new Text();
    private Text key = new Text();
    @Override
    public boolean parseJob(Mapper.Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        MultiPlatformDetectionRecord obj = (MultiPlatformDetectionRecord) model;
        StringBuilder sb = getBaseInfo(obj, successful,1);
        sb.append(obj.getMessage() == null ? "" : obj.getMessage()).append(CRT001);
        sb.append(obj.getCode() == null ? "" : obj.getCode()).append(CRT001);
        sb.append(obj.getTransactionId()==null?"":obj.getTransactionId()).append(CRT001);
        sb.append(obj.getPricingStrategy()==null?"":obj.getPricingStrategy()).append(CRT001);
        JSONObject jobj = obj.getData();
        if (obj==null){
            for (int i=1;i<=58;i++){
                sb.append("").append(CRT001);
            }
        }else {
            for (int i=1;i<=58;i++){
                sb.append(jobj.getString("GD_X_"+i)==null?"":jobj.getString("GD_X_"+i)).append(CRT001);
            }

        }
        key.set(getKey());
        val.set(sb.toString().replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_multi_platform_detection_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.MULTI_PLATFORM_DETECTION.toString();
    }

    @Override
    public String getComment() {
        return "多平台检测";
    }

    @Override
    public BaseModel getModel() {
        return new MultiPlatformDetectionRecord();
    }


}
